package global;

import entity.Temperature;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @author ypz
 * @date 2021/9/10 11:28
 */
public class GlobalObject {
    //私有构造,防止该类被示例化
    private GlobalObject(){}
    //创建对象
    private static  GlobalObject instance = new GlobalObject();
    //提供全局唯一的访问入口
    public static GlobalObject getInstance(){
        return instance;
    }

    private static final long ONE_DAY_MS = 1000*60*60*24;
    private static final Random RANDOM = new Random();

    public static String generateName() {
        char[] chars = new char[RANDOM.nextInt(5)+5];
        for(int i = 0; i < chars.length; i++){
            chars[i] = (char)(RANDOM.nextInt(26) + 65);
        }
        return new String(chars);
    }
    public static List<Temperature> generateTemperatures(
            int numTemps) {
        List<Temperature> temps = new ArrayList<>();
        for(int i = 0; i < numTemps; i++){
            long when = System.currentTimeMillis();
            when += ONE_DAY_MS*RANDOM.nextInt(365);
            Date d = new Date(when);
            Temperature t = new Temperature(
                    d,
                    new Float(
                            RANDOM.nextDouble()
                    )
            );
            temps.add(t);
        }
        return temps;
    }

}
